/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * TelaCadastro.java
 *
 * Created on 27/11/2011, 18:22:01
 */
package GUI;

import DAL.Conexao;
import javax.swing.JOptionPane;

/**
 *
 * @author Vanessa
 */
public class TelaCadastro extends javax.swing.JPanel {

    private String _nomeUsuario;
    private String _senhaUsuario;
    private Conexao cx = new Conexao();
    /** Creates new form TelaCadastro */
    public TelaCadastro() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        botaoParaCadastro = new javax.swing.JButton();
        cadastroUsuario = new javax.swing.JTextField();
        cadastroSenha = new javax.swing.JPasswordField();
        jLabel3 = new javax.swing.JLabel();

        setLayout(null);

        jLabel1.setFont(new java.awt.Font("Times New Roman", 1, 18));
        jLabel1.setForeground(new java.awt.Color(255, 255, 255));
        jLabel1.setText("Digite o usuário");
        add(jLabel1);
        jLabel1.setBounds(20, 110, 130, 24);

        jLabel2.setFont(new java.awt.Font("Times New Roman", 1, 18));
        jLabel2.setForeground(new java.awt.Color(255, 255, 255));
        jLabel2.setText("Digite a senha");
        add(jLabel2);
        jLabel2.setBounds(20, 140, 120, 17);

        botaoParaCadastro.setText("CADASTRAR");
        botaoParaCadastro.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botaoParaCadastroActionPerformed(evt);
            }
        });
        add(botaoParaCadastro);
        botaoParaCadastro.setBounds(80, 180, 120, 23);
        add(cadastroUsuario);
        cadastroUsuario.setBounds(160, 110, 110, 20);

        cadastroSenha.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cadastroSenhaActionPerformed(evt);
            }
        });
        add(cadastroSenha);
        cadastroSenha.setBounds(160, 140, 110, 20);

        jLabel3.setIcon(new javax.swing.ImageIcon("I:\\PI\\2012\\src\\GUI\\2012.jpg")); // NOI18N
        add(jLabel3);
        jLabel3.setBounds(0, 0, 570, 520);
    }// </editor-fold>//GEN-END:initComponents

    private void cadastroSenhaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cadastroSenhaActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_cadastroSenhaActionPerformed

    private void botaoParaCadastroActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botaoParaCadastroActionPerformed
        _nomeUsuario = this.cadastroUsuario.getText();
        _senhaUsuario = this.cadastroSenha.getText();
        if(_nomeUsuario.equals("") || _senhaUsuario.equals("")){
            JOptionPane.showMessageDialog(null, "Digite o usuário e a senha");
        }
        if(cx.existeJogador(_nomeUsuario)){
            JOptionPane.showMessageDialog(null, "Usuario ja existe");
        }
        else{
            cx.inserirJogadorBD(_nomeUsuario, _senhaUsuario);
            JOptionPane.showMessageDialog(null, "Usuario cadastrado");
        }
    }//GEN-LAST:event_botaoParaCadastroActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton botaoParaCadastro;
    private javax.swing.JPasswordField cadastroSenha;
    private javax.swing.JTextField cadastroUsuario;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    // End of variables declaration//GEN-END:variables
}
